package com.basic.backend.utils;

import com.basic.backend.common.ErrorCode;
import com.basic.backend.exception.BusinessException;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

public class WordParserUtil {

    public static String parseWordContent(MultipartFile file) {
        try (InputStream is = file.getInputStream()) {
            XWPFDocument doc = new XWPFDocument(is);
            XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
            return extractor.getText();
        } catch (Exception e) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "Word文件解析失败");
        }
    }


}